﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class BallCtrl : MonoBehaviour
{
    public static List<Vector3> touches;
    public Rigidbody rd;
    public void Start()
    {
        rd = GetComponent<Rigidbody>();
    }
    // Use this for initialization
    public void Check()
    {
        float minD = 999;
        Vector3 touch = Vector3.zero;
        for (int i = 0; i < touches.Count; i++)
        {
            float d = Vector3.Distance(transform.position, touches[i]);
            if (d < minD)
            {
                minD = d;
                touch = touches[i];
            }
        }
        if (minD < 1)
        {
            Vector3 dir = (transform.position - touch).normalized;
            //dir = new Vector3(dir.x, 0, dir.z).normalized;
            float d = 25f - minD;
            rd.AddForce(dir * d/2);
        }
    }
}
